/**
* <p> title �� UniversityServiceImpl.java</p>
* <p> package �� cn.edu.hit.education.service</p>
* <p> description ��TODO</p>
* <p> copyright �� ��������ҵ��ѧ(C) 2019</p>
* <p> company �� ��������ҵ��ѧAS&MT</p>
* <p> author �� ��ѩ�� jinxuesong@163.com</p>
* <p> date �� 2021��4��21�� ����4:36:14</p>
* <p> version �� v1.0 </p>
*
* Modification  History:
* Date         Author        Version        Discription
* -----------------------------------------------------------------------------------
* 2021��4��21��       ��ѩ��          1.0             1.0
* Why & What is modified: <�޸�ԭ������>
*/
package cn.edu.hit.education.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.hit.education.dao.UniversityMapper;
import cn.edu.hit.education.pojo.College;
import cn.edu.hit.education.pojo.University;
import cn.edu.hit.education.pojo.UniversityExample;

@Service
public class UniversityServiceImpl implements IUniversityService {
	@Autowired
	UniversityMapper universityMapper;
	@Autowired
	ICollegeService collegeService;

	@Override
	public int insert(University university) {
		return universityMapper.insert(university);
	}

	@Override
	public int deleteByPrimaryKey(int id) {
		return universityMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int update(University university) {
		return universityMapper.updateByPrimaryKey(university);
	}

	@Override
	public List<University> queryAllUniversity() {
		UniversityExample example = new UniversityExample();
		UniversityExample.Criteria criteria = example.createCriteria();
		criteria.andIdGreaterThan(0);
		
		return universityMapper.selectByExample(example);
	}

	@Override
	public University queryUniversityByPrimaryKey(int id) {
		// TODO Auto-generated method stub
		return universityMapper.selectByPrimaryKey(id);
	}

	@Override
	public int deleteByPrimaryKeyCascade(int id) {
		// TODO Auto-generated method stub
		List<College> colleges = collegeService.queryCollegesByUniversityId(id);
		if(colleges != null && colleges.size() > 0){
			for (College college : colleges) {
				collegeService.deleteByPrimaryKeyCascade(college.getId());
			}
		}
		return universityMapper.deleteByPrimaryKey(id);
	}

}
